<?php echo Modules::run('common/header') ?>

    <!-- Begin page content -->
    <div class="container content-body">
    	<div id="home">
            <div class="page-header" style="position:relative;">
                <h3>Dashboard</h3>
            </div>
            
            <?php 
			$user_id = Modules::run('auth/get_user_id');

			$store = $this->manager_model->get_store($user_id);
			
			?>
                    
            <div class="content-home">
                <div class="overview">
                    <div class="dashboard-heading">Overview</div>
                    <div class="dashboard-content">
                      <table class="table table-striped">
                        <tbody>
                            <tr>
                              <td>Total Sales:</td>
                              <?php $order_total = $this->manager_model->getTotalSales($store->toko_id); ?>
                              <td class="right"><?php echo 'Rp '.number_format($order_total->total_sales,2,',','.') ?></td>
                            </tr>
                            <tr>
                              <td>Total Sales This Year:</td>
                              <?php $get_total = $this->manager_model->getTotalSalesByYear(date('Y'), $store->toko_id); ?>
                              <td class="right"><?php echo 'Rp '.number_format($get_total->total_sales_year,2,',','.') ?></td>
                            </tr>
                            <tr>
                              <td>Total Sales (Status Order Paid):</td>
                              <?php $order_total = $this->manager_model->getTotalSalesPaid($store->toko_id); ?>
                              <td class="right"><?php echo 'Rp '.number_format($order_total->total_sales,2,',','.') ?></td>
                            </tr>
                            <tr>
                              <td>Total Sales This Year (Status Order Paid):</td>
                              <?php $get_total = $this->manager_model->getTotalSalesPaidByYear(date('Y'), $store->toko_id); ?>
                              <td class="right"><?php echo 'Rp '.number_format($get_total->total_sales_year,2,',','.') ?></td>
                            </tr>
                        </tbody>
                      </table>
                    </div>
                </div>
                <div class="statistic">
                    <div class="range">Select Range:          
                        <select id="range" onchange="getSalesChart(this.value)">
                            <option value="day">Today</option>
                            <option value="week">This Week</option>
                            <option value="month">This Month</option>
                            <option value="year">This Year</option>
                        </select>
                    </div>
                    <div class="dashboard-heading">Statistics</div>
                    <div class="dashboard-content">
                        
                    </div>
                </div>
                <div class="latest">
                <?php $user_id = Modules::run('auth/get_user_id');
		
					  $store = $this->manager_model->get_store($user_id); 
                      
                      $order = $this->manager_model->get_order_by_store($store->toko_id);
				?>
                    <div class="dashboard-heading">Latest 10 Orders</div>
                    <div class="dashboard-content">
                    <?php
					if(empty($order)){
							echo "<table class='table table-striped'>
									  <thead>
										<tr style='background:#E2E2E2;'>
											<th style='width: 15px;'><input type='checkbox'></th>
											<th>Order Code</th>
											<th>Customer</th>
											<th>Order Status</th>
											<th>Total</th>
											<th>Date Added</th>
											<th>Action</th>
										</tr>
									  </thead>
							</table>";
					}else{
					?>
                      <table class="table table-striped ">
                          <thead>
                            <tr style="background:#E2E2E2;">
                                <th>Order Code</th>
                                <th>Customer</th>
                                <th>Order Status</th>
                                <th>Total</th>
                                <th>Date Added</th>
                                <th>Action</th>	
                            </tr>
                          </thead>
                          <tbody>                
                            <?php foreach ($order as $keys => $row): ?>
                            <tr>
                                <td> <?php echo $row->order_cid; ?></td>
                                <td> <?php echo $row->firstname; ?> <?php echo $row->lastname ?> </td>
                                <?php $order_status = $this->manager_model->get_order_status(); ?>
                                <?php foreach ($order_status as $status){?>
                                    <?php if ($status->order_status_id == $row->order_status_id) {?>
                                        <td> <?php echo $status->name;?> </td>
                                    <?php } ?>
                                <?php } ?>
                                <td> <?php echo 'Rp '.number_format($row->total,2,',','.');?> </td>
                                <td> <?php echo $row->date_added;?> </td>
                                <td> <a href="<?php echo site_url('order/info/'.$row->order_id);?>">View</a><!-- | <a href="<?php echo site_url('order/update/'.$row->order_id);?>" >Edit</a>--></td>
            
                                
                            </tr>
                            <?php endforeach; ?>                 
                            
                          </tbody>
					</table>
                    <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    
    </div>

<?php echo Modules::run('common/footer') ?>